<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>03-02</title>
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
</head>
<body>
<div id="example">
    금액 : <span>{{amount}}원</span>
</div>
<script type="text/javascript">
var vm = new Vue({
    el : "#example",
    data : { amt : 1234567 },
    computed : {
        amount : {
            get : function() {
                var s = new String(""+this.amt);
                var result = "";
                var num = 0;
                for (var i=s.length-1; i>=0; i--) {
                    result = s[i] + result;
                    if (num % 3 == 2 && i !== 0)
                        result = "," + result;
                    num++;
                }
                return result;
            },
            set : function(amt) {
                if (typeof(amt) === "string") {
                    var result = parseInt(amt.replace(/,/g, ""))
                    if (isNaN(result)) this.amt = 0;
                    else   this.amt = result;
                } else if (typeof(amt) === "number")
                    this.amt = amt;
            }
        }
    }
});
</script>
</body>
</html>